import { defineStore } from 'pinia';
//卖家信息
interface shopState {
	// 具有索引签名的对象，属性不确定
	shopInfo : Record<string, any>;
	rechargeShop : Record<string, any>;
	// 其他状态变量
	sellerMemberId : any;
	qrsellerMemberId : any;
	changeShopType : string;
	localTime : number;
	oldGps : string;
	hasShut : boolean;
	shutTimes : string;
	shopConfig : any;
	shutStates : string;
	shutPhone : string;
	nowLocaGps : any;
	// costPlan : any;
	// liveSwitch:boolean;
	// mealTime:any;
	// changeCoups:any;
	// orderAgain:any;
	// sendDistance:any;
	// startDeliveryAmount:any;
	// packFee:any;
	// showSaleNum:boolean;
}
export const useShopStore = defineStore('shop', {
	state: () : shopState => ({
		shopInfo: {},
		rechargeShop: {},
		sellerMemberId: '',
		qrsellerMemberId: '',
		changeShopType: 'auto',//切换门店方式-手动/自动hand
		localTime: 0,
		oldGps: '',
		hasShut: false,//是否在营业
		shutTimes: '09:00-20:00',
		shopConfig: {},//门店配置
		shutStates: '',
		shutPhone: '',
		nowLocaGps: {
			lo: '',
			la: ''
		}
		// liveSwitch:false,
		// mealTime:{
		// 	preDeliverTime:'',//预计送达时间
		// 	readyMealTime:''//备餐时间
		// },
		// changeCoups:[],
		// orderAgain:false,
		// sendDistance:'',//门店配送距离
		// startDeliveryAmount:'',//门店多少起送
		// packFee:'',//打包费
		// showSaleNum:false,//是否显示销售数量
		// costPlan: '',//'1130'堂食,'1131'外卖,
	}),
	getters: {
		isFirstVisit: (state) => !state.sellerMemberId || !state.shopInfo.nmember_id ? true : false,
		curSellerMemberId: (state) => (state.qrsellerMemberId || state.sellerMemberId),
		getCurDlvType: (state) => {
			let r : any = '';
			if (state.shopConfig.fid && state.shopConfig.list && state.shopConfig.list.length > 0) {
				const cindex = state.shopConfig.list.findIndex(item => item.id == state.shopConfig.fid)
				cindex >= 0 ? r = state.shopConfig.list[cindex] : ''
			}
			return r
		},

	},
	actions: {
		setShop(info : Record<string, any>) {
			this.shopInfo = info;
			this.sellerMemberId = info.nmember_id || '';
		},
		setRechargeShop(info : Record<string, any>) {
			this.rechargeShop = info;
		},
		setQrShop(id : any) {
			this.qrsellerMemberId = id
		},
		setLocalTime(time : number) {
			this.localTime = time
		},
		setSlecShopType(type : string) {
			this.changeShopType = type;
			setTimeout(() => {
				this.changeShopType = 'auto'//暂
			}, 2000);
		},
		setOldGps(gps : string) {
			this.oldGps = gps
		},
		setHasShut(hasShut : boolean) {
			this.hasShut = hasShut
		},
		setShutStates(shutStates : string) {
			this.shutStates = shutStates
		},
		setShutTimes(shutTimes : string) {
			this.shutTimes = shutTimes
		},
		setShutPhone(shutPhone : string) {
			this.shutPhone = shutPhone
		},
		setShopConfig(r : any) {
			this.shopConfig = r
		},
		setCostPlan(costPlan : any) {
			this.costPlan = costPlan;
			this.shopConfig.fid = costPlan;
		},
		setNowLocaGps(nowLocaGps : any) {
			this.nowLocaGps.lo = nowLocaGps.lo
			this.nowLocaGps.la = nowLocaGps.la
		},
		// setLiveSwitch(liveSwitch:any){
		// 	this.liveSwitch=liveSwitch
		// },
		// setMealTime(mealTime:any){
		// 	this.mealTime.preDeliverTime=mealTime.preDeliverTime
		// 	this.mealTime.readyMealTime=mealTime.readyMealTime
		// },
		// setChangeCoups(changeCoups:any){
		// 	this.changeCoups=changeCoups
		// },
		// setOrderAgain(orderAgain:any){
		// 	this.orderAgain=orderAgain
		// },
		// setSendDistance(sendDistance:any){
		// 	this.sendDistance=sendDistance
		// },
		// setStartDeliveryAmount(startDeliveryAmount:any){
		// 	this.startDeliveryAmount=startDeliveryAmount
		// },
		// setPackFee(packFee:any){
		// 	this.packFee=packFee
		// },
		// setShowSaleNum(showSaleNum:any){
		// 	this.showSaleNum=showSaleNum
		// }
	},
	persist: {
		storage: {
			getItem: uni.getStorageSync,
			setItem: uni.setStorageSync
		},
		key: 'shopInfos',//本地存储key值
		paths: ['shopInfo', 'sellerMemberId', 'localTime', 'hasShut', 'shutTimes', 'shutStates', 'shutPhone', 'qrsellerMemberId', 'nowLocaGps']// 指定持久化的数据，不写默认持久化整个state
	}
});